package com.consumewebservice;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;

public class Testing {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Testing t=new Testing();
		t.postData();
	}
	
	public void postData() {
		// Create a new HttpClient and Post Header
		HttpClient httpclient = new DefaultHttpClient();
		HttpPost httppost = new      
		HttpPost("http://192.168.2.38:8080/STTHERESEREALTYWS/webresources/com.propertyportal.entities.person/createPerson/");

		try {
		     List <NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
		     //{firstName}/{lastName}/{birthday}/{mobile}/{landline}/{emailAddress}
		    nameValuePairs.add(new BasicNameValuePair("firstName", "adik"));
		    nameValuePairs.add(new BasicNameValuePair("lastName", "clang"));
		    nameValuePairs.add(new BasicNameValuePair("birthday", "2005-8-8"));
		    nameValuePairs.add(new BasicNameValuePair("mobile", "09486694316"));
		    nameValuePairs.add(new BasicNameValuePair("landline", "416-9965"));
		    nameValuePairs.add(new BasicNameValuePair("emailAddress", "2134@yahoo.com"));
		    


		    httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

		    // Execute HTTP Post Request
		    HttpResponse response = httpclient.execute(httppost);

		    if(response != null) {

		      int statuscode = response.getStatusLine().getStatusCode();

		       if(statuscode==HttpStatus.SC_OK) {
		        String strResponse = EntityUtils.toString(response.getEntity());
		        System.out.println("response:"+strResponse);
		      }
		   }

		 } catch (ClientProtocolException e) {
		  // TODO Auto-generated catch block
		  } catch (IOException e) {
		    // TODO Auto-generated catch block
		  }
		 }

}
